package com.xuhuan.thread.study2.lambda;

/**
 * @author huan.xu
 * @date 2021/9/29 11:27
 * @description lambda演化过程
 */
public class EvolutionDemo {

    static class Like2 implements IIlike {
        @Override
        public void lambda(int a) {
            System.out.println("I like lambda 参数[" + a + "]：静态内部类");
        }
    }

    public static void main(String[] args) {
        //1. new接口实现类
        IIlike like = new Like();
        like.lambda(1);

        //2. 静态内部类
        like = new Like2();
        like.lambda(2);

        //3. 局部内部类
        class Like3 implements IIlike {
            @Override
            public void lambda(int a) {
                System.out.println("I like lambda 参数[" + a + "]：局部内部类");
            }
        }
        like = new Like3();
        like.lambda(3);

        //4. 匿名内部类
        like = new IIlike() {
            @Override
            public void lambda(int a) {
                System.out.println("I like lambda 参数[" + a + "]：匿名内部类");
            }
        };
        like.lambda(4);

        //5. lambda简化
        like = (a) -> {
            System.out.println("I like lambda 参数[" + a + "]：lamdba表达式");
        };
        like.lambda(5);
    }
}

interface IIlike {
    void lambda(int a);
}

class Like implements IIlike {

    @Override
    public void lambda(int a) {
        System.out.println("I like lambda 参数[" + a + "]");
    }
}